"use strict";

const fs = require("node:fs");
const path = require("node:path");
const color = require("ansis");
const { diffJson } = require("diff");

const fileA = fs.readFileSync(
  path.resolve(__dirname, "./diff/filea.txt"),
  "utf8",
);
const fileB = fs.readFileSync(
  path.resolve(__dirname, "./diff/fileb.txt"),
  "utf8",
);

const diff = diffJson(fileA, fileB);
for (const part of diff) {
  // green for additions, red for deletions
  const text = part.added
    ? color.bgGreen(part.value)
    : part.removed
      ? color.bgRed(part.value)
      : part.value;
  process.stdout.write(text);
}
